2020-2021 Sunseeker Telemetry and Lighting System
ctsd16_ex2_singleChSingleConvPolling.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // MSP430FG662x Demo - CTSD16, Single Conversion on a Single Channel, Poll IFG
34 //
35 // Description: This program uses the CTSD16 module to perform a single
36 // conversion on a single channel. The CTSD16 interrupt flag for CH0 is polled
37 // to determine when a conversion has completed.
38 //
39 // Test by applying a voltage to the input channel and setting a breakpoint
40 // at the indicated line. Run program until it reaches the breakpoint, then use
41 // the debugger's watch window to view the conversion results.
42 //
43 // Results (upper 16 bits only) are stored in the variable "results"
44 //
45 // ACLK = 32kHz, MCLK = SMCLK = Calibrated DCO = 16.384MHz, SD_CLK = 1.024MHz
46 // * Ensure low_level_init.c is included when building/running this example *
47 //
48 // Notes: For minimum Vcc required for CTSD16 module - see datasheet
49 // 1nF cap btw Vref and AVss is recommended when using 1.2V ref
50 //
51 // MSP430FG662x
52 // -----------------
53 // /|\| |
54 // | | |
55 // --|RST |
56 // | |
57 // Vin1+ -->|P6.4/A0.0+ VREF |---+
58 // Vin1- -->|P6.5/A0.0- | |
59 // | | -+- 1nF
60 // | | -+-
61 // | | |
62 // | AVss |---+
63 //
64 //
74 //******************************************************************************
75 #include "inc/hw_memmap.h"
76 #include "wdt_a.h"
77 #include "gpio.h"
78 #include "ctsd16.h"
79 
80 uint32_t results; // CTSD16 Conversion Results
81 
82 void main(void) {
83  // Stop WDT
84  WDT_A_hold(WDT_A_BASE);
85 
86  // Select AD0+/- analog input pins
87  GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6, GPIO_PIN4 | GPIO_PIN5);
88 
89  // Initialize CTSD16 using internal reference and internal resistor for clock
90  CTSD16_init(CTSD16_BASE,
91  CTSD16_RTR_INPUT_CHARGEPUMP_BURST_REQUEST_DISABLE, CTSD16_REF_INTERNAL);
92 
93  // Initialize converter 0: AD0+ / AD0- as input, channel 9
94  CTSD16_initConverter(CTSD16_BASE, CTSD16_CONVERTER_0, CTSD16_SINGLE_MODE,
95  CTSD16_INPUT_CH9);
96 
97  // Delay ~120us for 1.2V ref to settle
98  __delay_cycles(2000);
99 
100  while(1) {
101  // Set bit to start conversion
102  CTSD16_startConverterConversion(CTSD16_BASE, CTSD16_CONVERTER_0);
103  // Poll IFG until conversion completes
104  while(!CTSD16_getInterruptStatus(CTSD16_BASE, CTSD16_CONVERTER_0, CTSD16_CONVERTER_INTERRUPT));
105  // Save CTSD16 conversion results
106  results = CTSD16_getResults(CTSD16_BASE, CTSD16_CONVERTER_0);
107  __no_operation(); // SET BREAKPOINT HERE
108  }
109 }
__no_operation()
__delay_cycles(500000)